package com.canal.admin.service.impl;

import com.canal.admin.dao.ZcolChannelItemMapper;
import com.canal.admin.dao.ZcolChannelMapper;
import com.canal.admin.service.ChannelBaseService;
import com.canal.admin.transfer.resp.canal.ChannelListResp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author yangbo
 * @date 2020-07-23 13:51
 */
@Service
@Slf4j
public class ChannelBaseServiceImpl implements ChannelBaseService {

    @Autowired
    private ZcolChannelMapper zcolChannelMapper;

    @Autowired
    private ZcolChannelItemMapper zcolChannelItemMapper;

    /**
     * 渠道列表
     * @param keyword
     * @return
     */
    @Override
    public List<Map<String, Object>> channelList(String keyword) {
        List<ChannelListResp> channelListRespList = zcolChannelMapper.findChannelByConditions(keyword);
        List<Map<String,Object>> resultList = new ArrayList<>(channelListRespList.size() + 1);
        for (ChannelListResp listResp : channelListRespList) {
            Map<String,Object> map = new HashMap<>(4);
            map.put("id",listResp.getId());
            map.put("name",listResp.getName());
            resultList.add(map);
        }
        return resultList;
    }

    @Override
    public List<Map<String, Object>> channelItemList(String keyword) {
        return zcolChannelItemMapper.searchByKw(keyword);
    }
}
